package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceDataListResult;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataResult;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.dto.FamilyAddDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.qpid.proton.codec.IntegerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public DeviceDataListResult<List<DeviceDataResult>> queryDeviceDataListByDay(DeviceDataDto dto) {
        List<DeviceDataResult> list = familyMemberService.queryDeviceDataList(dto);
        return DeviceDataListResult.success(list, null);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public DeviceDataListResult<List<DeviceDataByWeekResult>> queryDeviceDataListByWeek(DeviceDataDto dto) {
        List<DeviceDataByWeekResult> list = familyMemberService.queryDeviceDataByWeekList(dto);
        return DeviceDataListResult.success(list, null);
    }

    @PostMapping("/add")
    public AjaxResult addFamilyMember(@RequestBody FamilyAddDto dto) {
        familyMemberService.addFamilyMember(dto);
        return success();
    }

    @GetMapping("/my")
    public R<List<FamilyElderVo>> myFamilyMember(){
        return R.ok(familyMemberService.getElders());
    }

    @GetMapping("/list-by-page")
    public R<List<ElderDeviceVo>>listByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){

        return R.ok(familyMemberService.listByPage());
    }
//    public R<List<ElderDeviceVo>> listByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
//                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
//        return R.ok(familyMemberService.listByPage(pageNum,pageSize));
//    }
    @PostMapping("/QueryDevicePropertyStatus")
    public R<PropertiesVo<ProVo<DevicePropertiesVo>>> getDeviceProperties(@RequestBody Device device){
        PropertiesVo<ProVo<DevicePropertiesVo>> deviceProperties = familyMemberService.getDeviceProperties(device);
       return R.ok(deviceProperties);

    }

}
